package com.hzqy.web.ac.epg;

import com.hzqy.commons.utils.ExcelUtil;
import com.hzqy.commons.utils.ExcelUtil.MyEntry;
import com.hzqy.service.epg.AcWchatTvOrgService;
import com.hzqy.service.system.SysVoProcessServiceBeen;
import com.hzqy.web.vo.SysAreaStreetVo;
import com.hzqy.web.vo.epg.AcIntegralVo;
import com.hzqy.web.vo.epg.AcWchatTvGameVo;
import com.hzqy.web.vo.epg.AcWchatTvUserWeixinVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import sun.rmi.runtime.Log;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import java.util.*;

@Controller
@RequestMapping("/acWchatLink")
public class AcWchatTvOrgLinkAction {
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
    @Resource
	private AcWchatTvOrgService serviceAction;
    @Resource
	private SysVoProcessServiceBeen voProcessServiceBean;
    
    @RequestMapping("/acWchatLinkSelectAll")
	@ResponseBody
	public Object acSignSelect(String f_wtut_serverid,String f_wtut_phone,String f_sas_name,String f_wtut_nickname,int page,int rows){
    	Map<String,Object> listMap = new HashMap<String, Object>();
    	listMap.put("f_wtut_serverid", f_wtut_serverid);
    	listMap.put("f_wtut_phone", f_wtut_phone);
    	listMap.put("f_sas_name", f_sas_name);
    	listMap.put("f_wtut_nickname", f_wtut_nickname);
		listMap= serviceAction.selectAc(listMap,page, rows);
		return listMap;
	}
	@RequestMapping("/acWchatLinkSelectById")
	@ResponseBody
	public Object acSignSelect(String f_wtut_id){
		Map<String,Object> listMap = new HashMap<String, Object>();
		listMap.put("f_wtut_id",f_wtut_id);
		AcWchatTvUserWeixinVo vo= serviceAction.selectAcMes(listMap);
		return vo;
	}
	@RequestMapping("/acWcharUpdate")
	@ResponseBody
	public Object acupdate(AcWchatTvUserWeixinVo acVO){
		// 更新
		LOG.debug("信息更改："+acVO);
		Map<String,Object> map=new HashMap<String, Object>();
		AcWchatTvUserWeixinVo acv=new AcWchatTvUserWeixinVo();
		Integer update = serviceAction.update(acVO);
		if(update==1){
			map.put("success", true);
			map.put("result", "修改成功!");
		}else{
			map.put("success", true);
			map.put("result", "修改失败!");
		}
		return map;
	}
	@RequestMapping("/acWcharUnbind")
	@ResponseBody
	public Object acUnbind(String f_wtut_serverid){
    	// 解绑操作
		Map<String,Object> map=new HashMap<String, Object>();
		Integer unbind = serviceAction.unbind(f_wtut_serverid);
		if(unbind==1){
			 map.put("result","sucess");
		}else{
			map.put("result","false");
		}
		return map;
	}
	@RequestMapping("/acWcharbind")
	@ResponseBody
	public Object acbind(String f_wtut_serverid){
		Map<String,Object> map=new HashMap<String, Object>();
		Integer bind = serviceAction.bind(f_wtut_serverid);
		if(bind==1){
			map.put("result","sucess");
		}else{
			map.put("result","false");
		}
		return map;
	}
	@RequestMapping("/acWcharUnCheck")
	@ResponseBody
	public Object acUnCheck(String f_wtut_serverid){
		Map<String,Object> map=new HashMap<String, Object>();
		Integer uncheck = serviceAction.unCheck(f_wtut_serverid);
		if(uncheck==1){
			map.put("result","sucess");
		}else{
			map.put("result","false");
		}
		return map;
	}
	@RequestMapping("/acWcharCheck")
	@ResponseBody
	public Object acCheck(String f_wtut_serverid){
		Map<String,Object> map=new HashMap<String, Object>();
		Integer check = serviceAction.check(f_wtut_serverid);
		if(check==1){
			map.put("result","sucess");
		}else{
			map.put("result","false");
		}
		return map;
	}
	
	@RequestMapping("/wchatExcel")
	@ResponseBody
	public void wchatExcel(String f_wtut_serverid,String f_wtut_phone,String f_sas_name,String f_wtut_nickname,HttpServletResponse response){
		Map<String,Object> listMap = new HashMap<String, Object>();
    	listMap.put("f_wtut_serverid", f_wtut_serverid);
    	listMap.put("f_wtut_phone", f_wtut_phone);
    	listMap.put("f_sas_name", f_sas_name);
    	listMap.put("f_wtut_nickname", f_wtut_nickname);
		listMap= serviceAction.selectAc(listMap,1, 9999);
		List<AcWchatTvUserWeixinVo> list = new ArrayList<AcWchatTvUserWeixinVo>();
		list = (List<AcWchatTvUserWeixinVo>)listMap.get("rows");
		List<AcIntegralVo> list2 = new ArrayList<AcIntegralVo>();
		for (int i = 0; i < list.size(); i++) {
			AcIntegralVo acIntegralVo = new AcIntegralVo();
			acIntegralVo.setAiv_serviceId(list.get(i).getF_wtut_serverid());
			acIntegralVo.setAiv_name(list.get(i).getF_wtut_nickname());
			acIntegralVo.setAiv_sasDesc(list.get(i).getF_wtut_openid());
			acIntegralVo.setAiv_phone(list.get(i).getF_wtut_phone());
			acIntegralVo.setAiv_integralNum(list.get(i).getOrg().getF_wtgo_integral());
			acIntegralVo.setAiv_sasName(list.get(i).getStreet().getF_sas_name());
			acIntegralVo.setCreateTime(list.get(i).getF_wtut_cdate());
			acIntegralVo.setAiv_type(list.get(i).getF_wtut_memo());
			list2.add(acIntegralVo);
		}
		
		voProcessServiceBean.voProcess(list2);
		List<MyEntry<String, String>> excelCpHeader=new ArrayList<MyEntry<String, String>>();
		excelCpHeader.add(new MyEntry<String,String>("aiv_serviceId","业务帐号"));
		excelCpHeader.add(new MyEntry<String,String>("aiv_name","名称"));
		excelCpHeader.add(new MyEntry<String,String>("aiv_sasDesc","微信唯一标识"));
		excelCpHeader.add(new MyEntry<String,String>("aiv_phone","用户手机号"));
		excelCpHeader.add(new MyEntry<String,String>("aiv_integralNum","活动积分"));
		excelCpHeader.add(new MyEntry<String,String>("aiv_sasName","社区"));
		excelCpHeader.add(new MyEntry<String,String>("createTime","创建时间"));
		excelCpHeader.add(new MyEntry<String,String>("aiv_type","备注"));
		boolean flag=ExcelUtil.generateExcel(list2, excelCpHeader, response);
	}

}
